package main;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hichip.campro.R;
import com.hichip.sdk.HiChipSDK;

import activity.Left.LeftLocalFileActivity;
import activity.Left.LeftMoreActivty;
import base.HiFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import utils.HiTools;

public class LeftFragment extends HiFragment implements OnClickListener {
    @BindView(R.id.tv_app_version) TextView tv_app_version;
    @BindView(R.id.tv_sdk_version) TextView tv_sdk_version;
    @BindView(R.id.ll_left_local_file) LinearLayout ll_left_local_file;
    @BindView(R.id.iv_camera) ImageView iv_camera;
    @BindView(R.id.ll_left_more) LinearLayout ll_left_more;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_menu, null);
        ButterKnife.bind(this, view);
        findViews(view);
        setListeners();
        return view;
    }

    private void setListeners() {
        ll_left_local_file.setOnClickListener(this);
        ll_left_more.setOnClickListener(this);
    }


    public void findViews(View view) {
        if(HiTools.checkDeviceHasNavigationBar(getActivity())){
            RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
            params.setMargins(0,0,0,HiTools.dip2px(getActivity(),60));
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            tv_sdk_version.setLayoutParams(params);
        }
        try {
            PackageInfo packageInfo=getContext().getPackageManager().getPackageInfo(getContext().getPackageName(),0);
            tv_app_version.setText("V: "+packageInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        tv_sdk_version.setText(getString(R.string.sdk_version)+HiChipSDK.getSDKVersion());

        Glide.with(this).load(R.mipmap.ic_launcher).bitmapTransform(new CropCircleTransformation(getActivity())).crossFade(1000).into(iv_camera);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_left_local_file://本地文件
                Intent intent=new Intent(getActivity(), LeftLocalFileActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_left_more://更多
                intent=new Intent(getActivity(),LeftMoreActivty.class);
                startActivity(intent);
                break;
        }

    }
}
